package demo_0320;

import java.util.Arrays;
import java.util.Random;

public class Test {
    //生成有序数组
    public static void OrederArr(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            arr[i] = i;
        }
    }
    //生成随机数组
    public static void RandomArr(int[] arr){
        Random random = new Random();
        for (int i = 0; i < arr.length; i++) {
            arr[i] = random.nextInt(100000);
        }
    }
    //生成逆序数组
    public static void InorderArr(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            arr[i] = arr.length - i - 1;
        }
    }
    //插入排序测试
    public static void testInsertSort(int[] arr){
        int[] arr1 = Arrays.copyOf(arr,arr.length);
        long begin = System.currentTimeMillis();
        Sort.InsertSort(arr1);
        long end = System.currentTimeMillis();
        System.out.println("插入排序："+(end - begin));
    }
    //希尔排序测试
    public static void testShellSort (int[] arr) {
        int[] arr1 = Arrays.copyOf(arr,arr.length);
        long begin = System.currentTimeMillis();
        Sort.shellSort(arr1);
        long end = System.currentTimeMillis();
        System.out.println("希尔排序："+(end - begin));
    }
    //选择排序测试
    public static void testSelectSort (int[] arr) {
        int[] arr1 = Arrays.copyOf(arr,arr.length);
        long begin = System.currentTimeMillis();
        Sort.SelectSort1(arr1);
        long end = System.currentTimeMillis();
        System.out.println("选择排序："+(end - begin));
    }
    //测试快速排序
    public static void testQuickSort (int[] arr) {
        int[] arr1 = Arrays.copyOf(arr,arr.length);
        long begin = System.currentTimeMillis();
        Sort.quicksort(arr1);
        long end = System.currentTimeMillis();
        System.out.println("快速排序："+(end - begin));
    }
    public static void main(String[] args) {
        int[] arr = new int[100000];
        RandomArr(arr);
        testQuickSort(arr);

//        int[] arr1 = {3,4,6,7,8,9,1,2,5,10};
//        int[] arr2 = {10,5,2,1,4};
//        Sort.quicksort(arr1);
//        System.out.println(Arrays.toString(arr1));


//        Sort.heapSort(arr1);
//        System.out.println(Arrays.toString(arr1));

//        Sort.SelectSort1(arr2);
//        System.out.println(Arrays.toString(arr2));




//        testSelectSort(arr1);
//        Sort.SelectSort(arr1);
//        System.out.println(Arrays.toString(arr1));


//        OrederArr(arr);
//        testInsertSort(arr);
//        InorderArr(arr);
//        testInsertSort(arr);
//        testShellSort(arr);
//        RandomArr(arr);
//        testInsertSort(arr);
    }
}
